#include "defines.h"
#include "lib.h"
#include "kozos.h"
#include "udp.h"
#include "netdef.h"
#include "ntp.h"

void ntp_query(const uint8 server[])
{
    ntp_packet *np;

    np = kz_kmalloc(sizeof(ntp_packet));
    memset(np, 0, sizeof(*np));
    np->li_vn_mode = 0x23;

    udp_send((uint8 *)np, sizeof(ntp_packet), UDP_PORT_NTP, UDP_PORT_NTP, server);
    kz_kmfree(np);
}

ntp_time ntp_gettime(ntp_packet *np)
{
    ntp_time nt;
    uint32 t;

    t = np->tran_time_h;
    t = div3216(t, 60, &nt.sec);
    t = div3216(t, 60, &nt.min);
    t += 9; // 時差
    div3216(t, 24, &nt.hour);

    return nt;
}
